package echecs.tools;

public final class Board {

    private boolean _whiteActive = true;
    private boolean _whiteCastleShort = true;
    private boolean _whiteCastleLong = true;
    private boolean _blackCastleShort = true;
    private boolean _blackCastleLong = true;
    private Square _enPassant;
    private int _fullmoveNumber = 1;
    private int _halfmoveCount;
    private final Piece[][] _pieces = new Piece[8][8];

    Board() {
    }
//TODO supprimer ?

    public Piece[][] getPieces() {
        return _pieces;
    }

    public Piece getPieceAt(final Square pCase) {
        return getPieceAt(pCase.getFile(), pCase.getRank());
    }

    public Piece getPieceAt(final int pColonne, final int pLigne) {
        return _pieces[pColonne][pLigne];
    }

    void setPieceAt(final Piece pPiece, final Square pCase) {
        _pieces[pCase.getFile()][pCase.getRank()] = pPiece;
    }

    protected void setWhiteActive(final boolean pTrait) {
        _whiteActive = pTrait;
    }

    protected void setCastleLong(final boolean pBlanc, final boolean pEtat) {
        if (pBlanc) {
            _whiteCastleLong = pEtat;
        } else {
            _blackCastleLong = pEtat;
        }
    }

    protected void setCastleShort(final boolean pBlanc, final boolean pEtat) {
        if (pBlanc) {
            _whiteCastleShort = pEtat;
        } else {
            _blackCastleShort = pEtat;
        }
    }

    protected void setEnPassant(final Square pCase) {
        _enPassant = pCase;
    }

    protected void setFullmoveNumber(final int pNumero) {
        _fullmoveNumber = pNumero;
    }

    protected void setHalfmoveCount(final int pNombre) {
        _halfmoveCount = pNombre;
    }

    public final int getHalfmoveCount() {

        return _halfmoveCount;
    }

    public final int getFullmoveNumber() {

        return _fullmoveNumber;
    }

    public final boolean canCastleShort(final boolean pBlanc) {
        if (pBlanc) {
            return _whiteCastleShort;
        }

        return _blackCastleShort;
    }

    public final boolean canCastleLong(final boolean pBlanc) {
        if (pBlanc) {
            return _whiteCastleLong;
        }

        return _blackCastleLong;
    }

    public final Square getEnPassant() {
        return _enPassant;
    }

    public final boolean isWhiteActive() {
        return _whiteActive;
    }
}
